<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/login.css"/>
    <%
        //为了下面的value能拿到值，这里要提升值的作用域
        String username="";
        String password="";
        String ck="";
        //获取之前根目录下存储的所有cookie
        Cookie[] cookies = request.getCookies();
        if(cookies!=null && cookies.length>0){
            //遍历数组，逐一和拿key和标签的属性名对比
            for (Cookie cookie : cookies) {
                if("username".equals(cookie.getName())){
                    //名字对上了，就把值赋给这个遍变量
                    username=cookie.getValue();
                    //再给复选款属性赋值
                    ck="checked";
                }
                if("password".equals(cookie.getName())){
                    //名字对上了，就把值赋给这个遍变量
                    password=cookie.getValue();
                    //再给复选款属性赋值
                    ck="checked";
                }
            }
        }
    %>
</head>
<body>
    <!--顶部公司图标-->
    <div>
        <img src="img/logo.png"/>
    </div>

    <!--中间表单-->
    <div class="center">
        <form action="${pageContext.request.contextPath}/StudentServlet/login" method="post" >
            <table width="100%">
                <thead>
                    <tr>
                        <th colspan="2">账&nbsp;密&nbsp;登&nbsp;录<hr/></th>
                    </tr>
                </thead>

                <tbody>
                    <tr>
                        <td>
                            <label for="username">账号</label>
                        </td>
                        <td>
                            <input type="text" id="username" name="username" value="<%=username%>" placeholder=" 请输入账号" required/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="password">密码</label>
                        </td>
                        <td>
                            <input type="password" id="password" name="password" value="<%=password%>" placeholder=" 请输入密码" required/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="checkbox">记住状态</label>
                        </td>
                        <td>
                            <input type="checkbox" id="checkbox" name="ck" value="<%=ck%>"/>
                        </td>
                    </tr>
                </tbody>

                <tfoot>
                    <tr>
                        <td colspan="2">
                            <button type="submit">确&nbsp;定</button>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </form>
    </div>

    <!--底部页脚-->
    <div class="footer">
        <br/><br/>
        登录/注册即表示您同意&nbsp;&nbsp;
        <a href="#" target="_blank">用户协议</a>&nbsp;&nbsp;
        和&nbsp;&nbsp;
        <a href="#" target="_blank">隐私条款</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="#" target="_blank">忘记密码?</a>
    </div>
</body>
</html>